<style>
    table.movimentacao th th{font-size:10px; padding: 2px; border-top:none; color: silver;}
</style>

<a href="default/documento/index" class="pull-right btn btn-success">Voltar</a>
<div class="clearfix" style="margin-bottom:20px;"></div>

<?php if(count($this->data)):
    $data = $this->data; ?>
<div class="documento well" style="padding:5px;">
    <img style="float:left; position: relative;" 
        src="<?php echo $this->ServerUrl().'/'.$this->BaseUrl();?>/images/documento.png" />
    <div style="margin-left: 40px;">
        <b><?php preg_match('/([0-9]{5})([0-9]{6})([0-9]{4})([0-9]{2})/', $data['protocolo'], $matches);
            if($matches):
                    $protocolo = $matches[1].'.'.$matches[2].'/'.$matches[3].'-'.$matches[4];
                    echo $protocolo;
            endif;
        ?></b>                
        <span style="margin-left:20px;">
            <?php echo $data['tipo'].' - nº '.$data['numero'].'/'.$data['ano']; ?>
            <?php echo ' - '.$data['origem']; ?>
        </span>

        <span class="pull-right" style="margin-left:50px;"><a href="documento/form/id/<?php echo $data->id; ?>">Editar</a> | 
        <a href="documento/delete/id/<?php echo $data->id; ?>">Excluir</a></span><br/>
        <div>
            <div style="width:500px; float:left; margin-right: 20px;">
                <span style="font-size:11px; color: silver; margin: 0px;">Assunto</span><br/>
                    <?php echo $data['assunto']; ?><br/>
            </div>
            <div style="float:left; width: 330px;">
                <span style="font-size:11px; color: silver; margin: 0px;">Interessado</span><br/>
                <?php echo $data['interessado']; ?>
            </div>
            <div style="clear:both;"></div>
            <script>load('documento/movimentacao/doc_id/<?php echo $data['id'];?>');</script>

            <div class="well" style="padding:5px; margin:10px 10px 10px 0; background-color: white"  id="mov<?php echo $data['id'];?>">
                <span  style="float:right; position: relative;">
                <a class="cursor btnAdicionar" data-id ="<?php echo $data['id']?>" >
                    <img src="<?php echo $this->ServerUrl().$this->BaseUrl().'/images/adicionar.jpg'?>" />
                </a>
                </span>
                <div>
                    <?php $this->atual = $data; echo $this->render('documento/movimentacao.phtml'); ?>
                </div>
            </div>
        </div>
    </div>
</div>
<?php else: ?>
	<p class="alert alert-info">Não existem documentos cadastrados.</p>
<?php endif; ?>

        
<script>

botoes();

function botoes(){    

    $('.btnAdicionar').each(function(){
        $(this).removeClass('btnAdicionar');
        $(this).click(function(){
            var $doc = $(this);
            var $url = '<?php echo $this->ServerUrl().$this->baseUrl()?>/default/documento/form-movimentacao/doc_id/'+$doc.attr('data-id');
            $(this).parent().parent().find('.conteudo').load($url,null,function(){
                botoes();
            });
        });
    });
    
    $('.btnEditarMov').each(function(){
        $(this).removeClass('btnEditarMov');
        $(this).click(function(){
            var $mov = $(this);
            var $url = '<?php echo $this->ServerUrl().$this->baseUrl()?>/default/documento/form-movimentacao/id/'+$mov.attr('data-id');
            $(this).parent().parent().parent().parent().parent().find('.conteudo').load($url,null,function(){
                botoes();
            });
        });
    });
    
    $('.btnExcluirMov').each(function(){
        $(this).removeClass('btnExcluirMov');
        $(this).click(function(){
            var $mov = $(this);
            if (confirm('Deseja excluir a movimentação '+$mov.attr('data-texto')+'?')) {    
                var $url = '<?php echo $this->ServerUrl().$this->baseUrl()?>/default/documento/movimentacao-delete/id/'+$mov.attr('data-id');
                $(this).parent().parent().parent().load($url,null,function(){
                    botoes();
                });
            }
        });
    });
}
</script>

    